//
//  SNTrackSetViewController.m
//  project
//
//  Created by 圆圆陈 on 2017/12/13.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "SNTrackSetViewController.h"

@interface SNTrackSetViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSArray     *dataSourec;
@end

@implementation SNTrackSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 30+FitSimpleIpx(0, 20), 44, 44)];
    [backBtn setImageNormal:@"返回1"];
    [backBtn addTouchUpTarget:self action:@selector(backToLastVC)];
    [self.view addSubview:backBtn];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:SNFRAME(0, 64, HHHWIDTH, 25)];
    titleLabel.textColor     = SNCOLORBLACK;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font          = SNFONT(20.0);
    titleLabel.center        = CGPointMake(screenWidth/2, backBtn.center.y);
    titleLabel.text          = HHH_Text(@"跑道设置");
    [self.view addSubview:titleLabel];
    
    _tableView                = [[UITableView alloc]initWithFrame:CGRectMake(0, backBtn.bottom+10, HHHWIDTH, HHHHEIGHT-backBtn.bottom-10)];
    _tableView.delegate       = self;
    _tableView.dataSource     = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:_tableView];
    _dataSourec = @[HHH_Text(@"手机屏幕保持常亮"), HHH_Text(@"显示当前城市天气")];
}

- (void)backToLastVC {
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 82;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc]init];
    
    view.backgroundColor = SNCOLORSEPRATE;
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc]init];
    
    view.backgroundColor = SNCOLORSEPRATE;
    return view;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (!cell) {
        cell                = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.text = _dataSourec[indexPath.section];
    cell.textLabel.adjustsFontSizeToFitWidth = YES;
    ZJSwitch *button = [[ZJSwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 23)];
    button.tag = 100 +indexPath.section;
    if (indexPath.section == 1) {
        button.on = SN_USER.boolShoWeatherInfo;
    } else if (indexPath.section == 0) {
        button.on = SN_USER.boolLightScreen;
    }
    [button addTarget:self action:@selector(handleSwitchEvent:) forControlEvents:UIControlEventValueChanged];
    cell.accessoryView = button;
    
    return cell;
}

- (void)handleSwitchEvent:(ZJSwitch *)sender {
    switch (sender.tag) {
        case 100:
            SN_USER.boolLightScreen = sender.on;
            [SN_USER updateToDB];
            [[UIApplication sharedApplication] setIdleTimerDisabled:sender.on];
            break;
        case 101:
            SN_USER.boolShoWeatherInfo = sender.on;
            [SN_USER updateToDB];
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

